/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.rooster.test;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import org.rooster.manager.ResourceManager;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author HP
 */
public class ResourceMinMaxWorkingHourComparison {

    Connection con = null;
    final String url = "jdbc:mysql://localhost:3306/";
    final String db = "resources";
    final String driver = "com.mysql.jdbc.Driver";
    public String employeePriority;

    public Vector getWorkingHours() throws SQLException {
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ResourceRequirementComparison.class.getName()).log(Level.SEVERE, null, ex);
        }
        con = (Connection) DriverManager.getConnection(url + db, "root", "");

        Vector<Vector> employeeWorkingHours= new Vector<Vector>();

        for(int i=1;i<=ResourceManager.TOTAL_NO_OF_EMPLOYEES;i++){//employee Ids start from 1
            Vector workingHours= new Vector();
            PreparedStatement requirement = (PreparedStatement) con.prepareStatement("select * from  schedule where  assigned_resource='" +i+ "'");
            ResultSet requiremetResultSet = requirement.executeQuery();
            int assignedHours = 0;
            while (requiremetResultSet.next()) {
                assignedHours++;
            }
            workingHours.add(i);
            workingHours.add(assignedHours);
            employeeWorkingHours.add(workingHours);
        }
        if (con != null) {
            con.close();
        }
        System.out.println(employeeWorkingHours);
        return employeeWorkingHours;
    }
    public static void main(String[] args) throws SQLException {
        ResourceMinMaxWorkingHourComparison rmhc= new ResourceMinMaxWorkingHourComparison();
        rmhc.getWorkingHours();
    }
}
